package easy;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Solution_228 {

    public List<String> summaryRanges(int[] nums) {
        List<String> list = new ArrayList<>();
        if (nums==null || nums.length==0) {
            return list;
        }
        int begin = nums[0], pre = nums[0];
        for (int num : nums) {
            if (pre==num || (pre + 1) == num) {
                pre = num;
                continue;
            } else {
                StringBuilder builder = new StringBuilder();
                if (begin == pre) {
                    list.add(builder.append(begin).toString());
                } else {
                    list.add(builder.append(begin).append("->").append(pre).toString());
                }
                pre = num;
                begin = num;
            }
        }
        StringBuilder builder = new StringBuilder();
        if (begin == pre) {
            list.add(builder.append(begin).toString());
        } else {
            list.add(builder.append(begin).append("->").append(pre).toString());
        }
        return list;
    }

    public static void main(String[] args) {
        Solution_228 m = new Solution_228();
//        List<String> strings = m.summaryRanges(new int[]{0, 1, 2, 4, 5, 7});
        List<String> strings = m.summaryRanges(new int[]{0,0});
        for (String string : strings) {
            System.out.print(string + ",");
        }
        System.out.println();
    }
}
